//
//  OrderSquareCell.m
//  DaleTou
//
//  Created by candyxj on 2018/5/29.
//  Copyright © 2018年 geren. All rights reserved.
//

#import "OrderSquareCell.h"

@interface OrderSquareCell()

@property (weak, nonatomic) IBOutlet UIImageView *userIconImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLb;
@property (weak, nonatomic) IBOutlet UILabel *dateLb;


@property (weak, nonatomic) IBOutlet UILabel *numberLb;

@property (weak, nonatomic) IBOutlet UIImageView *seperIconImageView;

@property (weak, nonatomic) IBOutlet UILabel *moneyLb;
@property (weak, nonatomic) IBOutlet UILabel *getMoneyPercentLb;
@property (weak, nonatomic) IBOutlet UILabel *getMoneyLb;



@end



@implementation OrderSquareCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    self.userIconImageView.layer.cornerRadius = self.userIconImageView.frame.size.width / 2;
    self.userIconImageView.layer.masksToBounds = YES;
    
    
    self.seperIconImageView.image = [self imageWithLineWithImageView:self.seperIconImageView];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



-(void)setDataDic:(NSDictionary *)dataDic{
    
    _dataDic = dataDic;
//    @{@"userIconImage":@"1",@"name":@"user001",@"date":@"18-05-29 11:18",@"num":@"大乐透 第2018053期",@"money":@"2",@"moneyPercent":@"100",@"getMoney":@"200.00"}
    self.userIconImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_dataDic[@"userIconImage"]]];
    self.titleLb.text = [NSString stringWithFormat:@"%@",_dataDic[@"name"]];
    self.dateLb.text = [NSString stringWithFormat:@"%@",_dataDic[@"date"]];
    
    self.numberLb.text = [NSString stringWithFormat:@"%@",_dataDic[@"num"]];
    self.moneyLb.attributedText = [self setStringColorWithString:[NSString stringWithFormat:@"方案金额:%@元",_dataDic[@"money"]] AndWithloc:5 AndWithLength:[[NSString stringWithFormat:@"方案金额:%@元",_dataDic[@"money"]] length]];
    self.getMoneyPercentLb.attributedText = [self setStringColorWithString:[NSString stringWithFormat:@"本单盈利率:%@%%",_dataDic[@"moneyPercent"]] AndWithloc:6 AndWithLength:[[NSString stringWithFormat:@"本单盈利率:%@%%",_dataDic[@"moneyPercent"]] length]];
    self.getMoneyLb.attributedText = [self setStringColorWithString:[NSString stringWithFormat:@"税后奖金:%@元",_dataDic[@"getMoney"]] AndWithloc:5 AndWithLength:[[NSString stringWithFormat:@"税后奖金:%@元",_dataDic[@"getMoney"]] length]];
}



-(NSMutableAttributedString *)setStringColorWithString:(NSString *)string AndWithloc:(int )loc AndWithLength:(long )length{
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:string];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,5)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:244.0/255 green:114.0/255 blue:44.0/255 alpha:1.0] range:NSMakeRange(5,length - 5)];
    
    return str;
}






-(UIImage *)imageWithLineWithImageView:(UIImageView *)imageView{
    
    CGFloat width = imageView.frame.size.width;
    CGFloat height = imageView.frame.size.height;
    UIGraphicsBeginImageContext(imageView.frame.size);
    [imageView.image drawInRect:CGRectMake(0, 0, width, height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGFloat lengths[] = {2,1};
    CGContextRef line = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(line, [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0].CGColor);
    CGContextSetLineDash(line, 0, lengths, 1);
    CGContextMoveToPoint(line, 0, 1);
    CGContextAddLineToPoint(line, width-10, 1);
    CGContextStrokePath(line);
    return  UIGraphicsGetImageFromCurrentImageContext();
}





@end





